package ar.com.photo_admin.domain

class UserLogin {

	def userService
	
	String userId
	
	String password
	
	static constraints = {
		userId(blank:false)
		password(blank:false)
		
		userId validator: { userId, obj ->
			return userId?.isEmpty() || obj.userService.findByUsernameOrEmail(userId) != null
		}
		
		password validator: { password, obj ->
			User user = obj.userService.findByUsernameOrEmail(obj.userId)
			return password?.isEmpty() || user == null || (user != null && password == user.password)
		}
	}
}
